﻿using System;
using System.IO;
using Microsoft.Practices.EnterpriseLibrary.ExceptionHandling;
using Microsoft.Practices.EnterpriseLibrary.Logging;
using Microsoft.Practices.EnterpriseLibrary.Validation;
using Microsoft.Practices.ServiceLocation;
using Microsoft.Practices.Unity;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using vm.Aspects.Exceptions;
using vm.Aspects.Facilities;

namespace vm.Aspects.Tests
{
    [TestClass]
    public class DumpExceptionFormatterTest
    {
        public TestContext TestContext { get; set; }

        [TestMethod]
        public void FormatTest()
        {
            string formattedMessage;

            using (var writer = new StringWriter())
                try
                {
                    throw new BusinessException("Test exception");
                }
                catch (BusinessException x)
                {
                    var target = new DumpExceptionFormatter(writer, x, Guid.NewGuid());

                    target.Format();
                    writer.Flush();

                    formattedMessage = writer.GetStringBuilder().ToString();
                    TestContext.WriteLine(formattedMessage);
                }

            Assert.IsTrue(!string.IsNullOrWhiteSpace(formattedMessage));
        }
    }
}
